﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WaveTagLibrary;

namespace Tester
{
	class Program
	{
		static void Main(string[] args)
		{
			new Program().Run();
		}

		private async void Run()
		{
			Console.WriteLine("Loading files...");

			string[] filenames = Directory.GetFiles("<location>", "*.wav", SearchOption.AllDirectories);

			var waveFiles = filenames.Select(f => new WaveFile(f)).ToArray();

			foreach (var file in waveFiles)
				await file.LoadAsync();

			Console.WriteLine("Editing files...");

			foreach (var waveFile in waveFiles)
			{
				await ProcessFile(waveFile);
				Console.WriteLine(waveFile.Filename);
			}

			Console.WriteLine("Done!");
		}

		private async Task ProcessFile(WaveFile waveFile)
		{
			waveFile.SetTagValue("IART", "Artist");
			waveFile.SetTagValue("INAM", Path.GetFileNameWithoutExtension(waveFile.Filename).Substring(3)); // remove the 3 first characters
			waveFile.SetTagValue("IPRD", "Album");
			waveFile.SetTagValue("IGNR", "Genre");

			waveFile.Tags.RemoveAll(t => t.TagName == "ITOC"); // remove table of content
			
			await waveFile.SaveAsync(); // save
		}
	}
}
